limsIndex.editPage = {

    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-index-edit-list-grid',
            url : limsIndex.baseUrl + '/queries',
            requestData: {
                status_EQ: '1'
            },
            service : 'limsIndexServiceImpl',
            dbTable : 'T_LIMS_INDEX',
            columns : limsIndex.getEditListColumns(),
            page: true,
            deleteFormatter: function(row) {
                return row.indexCode;
            },
            onLoadSuccess : function(data) {
            },
            onRowActive : function(index, row) {
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    Gikam.preInsert({
                        height: 380,
                        modalTitle : 'GIKAM.BUTTON.INSERT',
                        fields : limsIndex.getBaseInfoFormFields(),
                        disableNotEmptyValidate: true,
                        titleWidth : 100,
                        url : limsIndex.baseUrl
                    }).done(function() {
                        Gikam.getComp('lims-index-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-index-edit-list-grid').deleteRows(limsIndex.baseUrl);
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DEACTIVE',
                icon : 'disable',
                onClick : function () {
                    _this.updateStatusRows('0');
                }
            } ]
        }
    },

    getDisabledGridParam: function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-index-disable-edit-list-grid',
            url : limsIndex.baseUrl + '/queries',
            requestData: {
                status_EQ: '0'
            },
            service : 'limsIndexServiceImpl',
            dbTable : 'T_LIMS_INDEX',
            columns : limsIndex.getEditListColumns(),
            page: true,
            onLoadSuccess : function(data) {
            },
            onRowActive : function(index, row) {
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.ACTIVE',
                icon : 'enable',
                onClick : function () {
                    _this.updateStatusRows('1');
                }
            } ]
        }
    },

    updateStatusRows : function(status){
        let grid;
        let grid2;
        let message;
        if (status === '0') {
            grid = Gikam.getComp('lims-index-edit-list-grid');
            grid2 = Gikam.getComp('lims-index-disable-edit-list-grid');
            message = Gikam.propI18N('GIKAM.TIP.CONFIRM_TO_DEACTIVATE');
        } else {
            grid = Gikam.getComp('lims-index-disable-edit-list-grid');
            grid2 = Gikam.getComp('lims-index-edit-list-grid');
            message = Gikam.propI18N('GIKAM.TIP.CONFIRM_TO_ACTIVATE');
        }
        let selections = grid.getSelections();
        if (Gikam.isEmpty(selections)){
            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
            return;
        }
        Gikam.confirm('GIKAM.BUTTON.CONFIRM', message, function () {
            workspace.window.showMask();
            Gikam.postText(limsIndex.baseUrl + '/update/status',
                Gikam.getJsonWrapper({status : status}, ['', selections])).done(function () {
                    grid.refresh();
                    grid2.refresh();
            }).always(function () {
                workspace.window.closeMask();
            });
        })
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-index-edit-list-layout',
            renderTo : workspace.window.$dom,
            center : {
                items : [{
                    type: 'tab',
                    panels: [{
                        title: 'GIKAM.ACTIVE.STATUS.YES',
                        items: [_this.getGridParam()]
                    }, {
                        title: 'GIKAM.ACTIVE.STATUS.NO',
                        items: [_this.getDisabledGridParam()]
                    }]
                }]
            }
        });
    },

    init : function() {
        this.create();
    }
};
